package io.kimmking.dubbo.demo.second.consumer.listeners;

import io.kimmking.common.rocketmq.repository.DistrbuitedTxProducerWrapper;
import io.kimmking.dubbo.common.entity.Order;
import io.kimmking.dubbo.common.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;

@Slf4j
@RocketMQTransactionListener
public class CancalOrderListener extends DistrbuitedTxProducerWrapper {

    @DubboReference(version = "1.0.0")
    OrderService orderService;

    /**
     * 执行本地事务方法
     * @param o  业务对象
     * @return
     */
    @Override
    protected boolean localTransactionExecutor(Object... o) {

        Order order = (Order)o[0];
        order.setOrderStatus(1);
        //将订单状态置为无效状态(即状态字段值为1)
        return orderService.saveOrUpdate(order);
    }
}
